/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-explicit-any */
// 定义一个依赖标识
const SERVICE_TOKEN = "MyService";

function Injectable(): ClassDecorator {
  return <T extends object>(target: T) =>
    // 标记类为可注入
    // Reflect.defineMetadata(SERVICE_TOKEN, target, target);
    target;
}

// 参数装饰器标记需要注入的依赖
function InjectMyService() {
  return (target: any, methodName: string, parameterIndex: number) => {
    // 记录参数索引对应的依赖标识
    Reflect.defineMetadata(SERVICE_TOKEN, parameterIndex, target, methodName);
  };
}
type InjectFixType<T, K extends string> = T & Record<K, any>;

// 服务类
class MyService {
  doWork(): void {
    console.log("Work done!");
  }
}

// 使用类
@Injectable()
class Consumer {
  action(@InjectMyService() service: MyService): void {
    service.doWork();
  }
}

// 依赖注入逻辑（简化版）
const instance: Consumer = new Consumer();
const methodName = "action";
const paramIndex = Reflect.getMetadata(SERVICE_TOKEN, instance, methodName);

console.log("paramIndex", paramIndex);

const service = new MyService();
instance[methodName](service); // 输出: Work done!

class A {
  A(): void;
  A() {}
}

export { instance };
